package com.oppo.userServer.presentationO.controller;

import com.oppo.userServer.application.service.UserService;
import com.oppo.userServer.common.CommonResult;
import com.oppo.userServer.presentationO.converter.UserParamVOConverter;
import com.oppo.userServer.presentationO.vo.UserParamVO;
import com.oppo.userServer.presentationO.vo.UserResultVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 清梦
 * @version 1.0.0
 * @Description user控制层
 * @createTime 2024年03月11日 22:51:00
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 获取用户列表
     *
     * @param userParamVO 用户 param vo
     * @return {@link CommonResult }<{@link List }<{@link UserResultVO }>>
     * @author qingmeng
     * @createTime: 2024/03/11 23:32:22
     */
    @GetMapping("/getUserList")
    public CommonResult<List<UserResultVO>> getUserList(UserParamVO userParamVO) {
        List<UserResultVO> list = userService.getUserList(UserParamVOConverter.converterUserParamVOToUserDTO(userParamVO));
        return CommonResult.success(list);
    }

    @PostMapping
    public CommonResult<String> addUser() {
        userService.addUser();
        return CommonResult.success();
    }
    @PutMapping
    public CommonResult<String> editUser() {
       userService.editUser();
        return CommonResult.success();
    }
    @DeleteMapping("{id}")
    public CommonResult<String> getUserList(@PathVariable Long id) {
        userService.removeById(id);
        return CommonResult.success();
    }
}
